home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH13 / LEXER.ASM < prev   
Encoding:
Assembly Source File  |  1996-02-24  |  2.5 KB  |  105 lines

  1. ; Lexer.asm
  2. ;
  3. ; This program displays the individual components on a DOS command line.
  4.  
  5.         include        stdlib.a
  6.         includelib    stdlib.lib
  7.  
  8. cseg        segment        byte public 'CODE'
  9.         assume        cs:cseg, ds:dseg, es:dseg, ss:sseg
  10.  
  11. ; Equates into command line-
  12.  
  13. CmdLnLen    equ    byte ptr es:[80h]    ;Command line length
  14. CmdLn        equ    byte ptr es:[81h]    ;Command line data
  15.  
  16. tab        equ    09h
  17.  
  18. MainPgm        proc    far
  19.  
  20. ; Properly set up the segment registers:
  21.  
  22.         push    ds            ;Save PSP
  23.         mov    ax, seg dseg
  24.         mov    ds, ax
  25.         pop    PSP
  26.  
  27. ;---------------------------------------------------------------
  28.  
  29.         print
  30.         byte    cr,lf
  31.         byte    'Items on this line:',cr,lf,lf,0
  32.  
  33.         mov    es, PSP             ;Point ES at PSP
  34.         lea    bx, CmdLn        ;Point at command line
  35. PrintLoop:    print
  36.         byte    cr,lf,'Item: ',0
  37.         call    SkipDelimiters        ;Skip over leading delimiters
  38. PrtLoop2:    mov    al, es:[bx]        ;Get next character
  39.         call    TestDelimiter        ;Is it a delimiter?
  40.         jz    EndOfToken        ;Quit this loop if it is
  41.         putc                ;Print char if not.
  42.         inc    bx            ;Move on to next character
  43.         jmp    PrtLoop2
  44.  
  45. EndOfToken:    cmp    al, cr            ;Carriage return?
  46.         jne    PrintLoop        ;Repeat if not end of line
  47.  
  48.         print
  49.         byte    cr,lf,lf
  50.         byte    'End of command line',cr,lf,lf,0
  51.         ExitPgm
  52. MainPgm        endp
  53.  
  54. ; The following subroutine sets the zero flag if the character in 
  55. ; the AL register is one of DOS' six delimiter characters, 
  56. ; otherwise the zero flag is returned clear. This allows us to use 
  57. ; the JE/JNE instructions afterwards to test for a delimiter.
  58.  
  59. TestDelimiter    proc    near
  60.         cmp    al, ' '
  61.         jz    ItsOne
  62.         cmp    al,','
  63.         jz    ItsOne
  64.         cmp    al,Tab
  65.         jz    ItsOne
  66.         cmp    al,';'
  67.         jz    ItsOne
  68.         cmp    al,'='
  69.         jz    ItsOne
  70.         cmp    al, cr
  71. ItsOne:        ret
  72. TestDelimiter    endp
  73.  
  74. ; SkipDelimiters skips over leading delimiters on the command 
  75. ; line. It does not, however, skip the carriage return at the end 
  76. ; of a line since this character is used as the terminator in the 
  77. ; main program.
  78.  
  79. SkipDelimiters    proc    near
  80.         dec    bx            ;To offset INC BX below
  81. SDLoop:        inc    bx            ;Move on to next character.
  82.         mov    al, es:[bx]        ;Get next character
  83.         cmp    al, 0dh         ;Don╒t skip if CR.
  84.         jz    QuitSD
  85.         call    TestDelimiter        ;See if it╒s some other
  86.         jz    SDLoop            ; delimiter and repeat.
  87. QuitSD:        ret
  88. SkipDelimiters    endp
  89.  
  90. cseg        ends
  91.  
  92. dseg        segment    byte public 'data'
  93.  
  94. PSP        word    ?            ;Program segment prefix
  95. dseg        ends
  96.  
  97. sseg        segment    byte stack 'stack'
  98. stk        word    0ffh dup (?)
  99. sseg        ends
  100.  
  101. zzzzzzseg    segment    para public 'zzzzzz'
  102. LastBytes    byte    16 dup (?)
  103. zzzzzzseg    ends
  104.         end    MainPgm
  105.